package agriculture.mapper;

import agriculture.bean.Comment;
import agriculture.bean.Product;
import agriculture.dto.StockDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface ProductMapper extends BaseMapper<Product> {

    // 查询所有 status 为 1（上架）的商品
    @Select("SELECT id, title, img_url AS imgUrl, price, paid_count AS paidCount, description, category_id AS categoryId, stock, region, brand, status, create_time AS createTime, update_time AS updateTime FROM product WHERE status = 1")
    List<Product> findAllActiveProducts();

    List<Product> findProductsByCategory(Long categoryId); // 新增根据商品的分类查询数据

    //查询商品详情
    List<Product> selectProductDetail(@Param("id") Long id);


    List<Comment> getCommentsByProductId(@Param("productId") Long productId);
}
